package com.sdcqjy.property.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;

import com.sdcqjy.mylibrary.widget.ShowToast;
import com.sdcqjy.property.R;
import com.sdcqjy.property.base.SimpleBaseActivity;
import com.sdcqjy.property.presenter.ChangePresenter;
import com.sdcqjy.property.presenter.contract.ChangeContract;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 描述：
 * Created by rookieCi on 2017/9/22.
 */
public class ChangePwdActivity extends SimpleBaseActivity<ChangePresenter> implements ChangeContract.View {
    @BindView(R.id.editOldPwd)
    EditText editOldPwd;
    @BindView(R.id.editPwd)
    EditText editPwd;
    @BindView(R.id.editPwd2)
    EditText editPwd2;

    public static void open(Context context) {
        Intent intent = new Intent(context, ChangePwdActivity.class);
        context.startActivity(intent);
    }

    protected int backBtn() {
        return R.id.imgBack;
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_pwd);
        ButterKnife.bind(this);
        presenter = new ChangePresenter(this);
    }

    public void changeSucc() {
        onBackPressed();
    }

    @OnClick(R.id.btnLogin)
    public void onViewClicked() {
        String oldPwd = editOldPwd.getText().toString();
        if (TextUtils.isEmpty(oldPwd)) {
            ShowToast.alertShortOfWhite(getActivity(), R.string.qsrysmm);
            return;
        }
        String pwd = editPwd.getText().toString();
        if (TextUtils.isEmpty(pwd)) {
            ShowToast.alertShortOfWhite(getActivity(), R.string.qszxmm);
            return;
        }
        String pwd2 = editPwd2.getText().toString();
        if (TextUtils.isEmpty(pwd2)) {
            ShowToast.alertShortOfWhite(getActivity(), R.string.qzcsrxmm);
            return;
        }
        if (!pwd.equals(pwd2)) {
            ShowToast.alertShortOfWhite(getActivity(), R.string.ncsrdmmbt);
            return;
        }
        presenter.changePwd(oldPwd, pwd);
    }
}
